class Solution {
public:
    string multiply(string num1, string num2) {
        reverse(num1.begin(),num1.end());
        reverse(num2.begin(),num2.end());
        int m=num1.size();
        int n=num2.size();
        vector<long long> tmp(m+n);
        for(int i=0;i<m;++i)
        {
            for(int j=0;j<n;++j)
            {
                tmp[i+j]+=(num1[i]-'0')*(num2[j]-'0');
            }
        }

        int x=0;
        int cur=0;
        string ret;
        while(cur<m+n-1||x!=0)
        {
            if(cur<m+n-1)
            {
                x+=tmp[cur++];
            }
            ret+=x%10+'0';
            x/=10;
        }

        while(ret.size()>1&&ret.back()=='0')
        {
            ret.pop_back();
        }
        reverse(ret.begin(),ret.end());
        return ret;
    }
};
